<?php

class MpController extends Zend_Controller_Action
{
    function init()
    {
        $this->db = Zend_Registry::get("db");
    }
	
    private function checkSignature()
    {
    
    	$signature = $_GET["signature"];
    	$timestamp = $_GET["timestamp"];
    	$nonce = $_GET["nonce"];
    	$this->token="wechat";
    	$token = "lwkEhdSalf8wrfs";
    	$tmpArr = array($token, $timestamp, $nonce);
    	// use SORT_STRING rule
    	sort($tmpArr, SORT_STRING);
    	$tmpStr = implode( $tmpArr );
    	$tmpStr = sha1( $tmpStr );
    
    	if( $tmpStr == $signature ){
    		return true;
    	}else{
    		return false;
    	}
    }
    
    
	function indexAction()
	{
		
 		$echoStr = $_GET["echostr"];
		
		//valid signature , option
		if($this->checkSignature()){
		    echo $echoStr;
		    exit;
		}
	}
}